<?php

use Jialeo\LaravelSchemaExtend\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateAdminsTable extends Migration
{
    private $table = 'admins';

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable($this->table)) {
            Schema::create($this->table, function (Blueprint $table) {
                $table->charset = 'utf8';
                $table->collation = 'utf8_general_ci';
                $table->comment = '管理员表';
                $table->increments('id')->comment('主键');
                $table->string('account', 100)->unique()->comment('账户名称');
                $table->string('password', 255)->comment('账户密码');
                $table->char('mobile', 11)->default('')->unique()->comment('手机号码');
                $table->string('email', 255)->default('')->unique()->comment('邮箱');
                $table->string('post', 100)->default('')->comment('职务');
                $table->unsignedInteger('role')->default(0)->comment('账户角色');
                $table->unsignedTinyInteger('state')->default(1)->comment('账户状态 1:启用, 2:禁用');
                $table->ipAddress('login_ip')->default('0.0.0.0')->comment('最后登录IP');
                $table->timestamp('login_time')->nullable()->comment('最后登录时间');
                $table->timestamps();
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        if (Schema::hasTable($this->table)) {
            Schema::dropIfExists($this->table);
        }
    }
}
